import { defineConfig } from 'vite'
import path from 'path'
// import path from "path-browserify";
import vue from '@vitejs/plugin-vue'
import eslint from 'vite-plugin-eslint'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    eslint({
      cache: false,
      exclude: ['**/node_modules/**']
    }),
    createSvgIconsPlugin({
      // 指定图标存放的目录
      iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
      // 指定symbolId格式
      symbolId: 'icon-[name]',
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      // path: "path-browserify",
    },
    extensions: [
      '.mjs',
      '.js',
      '.ts',
      '.jsx',
      '.tsx',
      '.json',
      '.vue'
    ]
  },
  css: {
    preprocessorOptions: {
      scss: {
        javascriptEnabled: true,
        additionalData: `
        @use "@/styles/variables.scss" as *;
        @use "@/styles/mixins.scss" as *;
        `,
        api: 'modern-compiler'
      },
    },
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:3001',   // 目标服务器地址
        changeOrigin: true,                // 修改请求头中的 Origin 为目标地址
        rewrite: (path) => path.replace(/^\/api/, '') // 重写路径，移除 '/api' 前缀
      }
    }
  }
})
